package com.mvc.service.impl;

import com.mvc.entity.Type;
import com.mvc.mapper.TypeMapper;
import com.mvc.service.TypeService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @ProjectName: dior
 * @Package: com.mvc.service.impl
 * @ClassName: TypeServiceImpl
 * @Description: TODO
 * @Author: Bang
 * @Date: 2021/11/27 11:35
 * @Version: 1.0
 **/
@Service
public class TypeServiceImpl implements TypeService {

    @Resource
    TypeMapper typeMapper;

    @Override
    public List<Type> query() {
        //查询一级菜单
        List<Type> typeList = typeMapper.selectByFather(0);
        for(Type firstType:typeList){
            firstType.setChildren(typeMapper.selectByFather(firstType.getId()));
            for (Type secondType:firstType.getChildren()){
                secondType.setChildren(typeMapper.selectByFather(secondType.getId()));
            }
        }
        return typeList;
    }

    @Override
    public Integer add(Type type) {
        return typeMapper.add(type);
    }
}
